#include "StringTools.h"

QString toQString(const std::wstring& str)
{	
	return toQString(str.c_str(), str.length());
}

QString toQString(const wchar_t* str, int length)
{
	//return QString::fromWCharArray(str, length);

	QString res;
	for (int i = 0; i < length; ++i)
		res += (char)str[i];
	return res;
}

std::wstring toWString(const QString& str)
{
	// return str.toStdWString();
	QByteArray arr = str.toAscii();
	std::wstring res;
	res.assign(arr.begin(), arr.end());
	return res;
}

void toCString(const QString& str, wchar_t* buffer)
{
	//buffer[str.toWCharArray(buffer)] = 0;
	int pos = 0;
	foreach (QChar ch, str)
	{
		buffer[pos++] = ch.toAscii();
	}
	buffer[pos] = '\0';
}

std::string toString(std::wstring wstr)
{
	std::string str;
	str.assign(wstr.begin(), wstr.end());
	return str;
}

std::string toString(const wchar_t* arr)
{
	std::string str;
	str.assign(arr, arr + wcslen(arr));
	return str;
}
